package com.mangoqueen.game.BearBabyDaily;

import java.lang.ref.WeakReference;

import org.cocos2dx.lib.Cocos2dxActivity;

import android.os.Handler;
import android.os.Message;
import android.os.Bundle;
import com.playhaven.android.*;
import com.playhaven.android.req.*;
import com.playhaven.android.view.*;

public class PlayHavenHelper implements PlacementListener
{
  protected static final int START_LIST            = 1;

  protected Cocos2dxActivity mActivity;
  protected static Handler mHandler;

  public PlayHavenHelper(Cocos2dxActivity activity)
  {
    mActivity = activity;
    initJNI(new WeakReference<PlayHavenHelper>(this));

    try
    {
      PlayHaven.configure(mActivity, "602ba6f0543649c09ae7714bf5590d9f", "e8eeca6833ed42a695dc9bd4da310082");
      OpenRequest open = new OpenRequest();
      open.send(mActivity);

      Placement placement = new Placement("moregame");
      placement.setListener(this);
      placement.preload(mActivity);
    } catch(PlayHavenException e)
    {
    }

    mHandler = new Handler()
    {
        public void handleMessage(Message msg)
        {
            switch (msg.what)
            {
              case START_LIST:
                mActivity.startActivity(FullScreen.createIntent(mActivity, (String)msg.obj));
                break;
              default:
                super.handleMessage(msg);
                break;
            }
        }
    };
  }

  private native void initJNI(Object wadk_this);

  private static void nativeStartList(String tags)
  {
    Message msg = new Message();
    msg.what = START_LIST;
    msg.obj = tags;
    mHandler.sendMessage(msg);
  }

  public void contentLoaded(Placement placement)
  {
  }

  public void contentFailed(Placement placement, PlayHavenException e)
  {
  }

  public void contentDismissed(Placement placement, PlayHavenView.DismissType dismissType, Bundle data)
  {
  }
}
